<form id="add-form" class="form-horizontal form-ajax" role="form" data-toggle="validator" method="POST" action="">

    <div class="form-group">
        <label for="num" class="control-label col-xs-12 col-sm-2">你输入你想生成的数量:</label>
        <div class="col-xs-12 col-sm-8">
            <input type="text" name="num" id="num" class="form-control" placeholder="二维码数量" />
        </div>
    </div>
    <div class="form-group">
        <label style="color:red; " class=" control-label col-xs-12 col-sm-2">温馨提示：一次最多生成500张</label>
    </div>

<!--    <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">-->
<!--        <label for="" id="down_progress_lable" class="control-label col-xs-4">正在打包(0%)</label>-->
<!--        <div class="col-xs-8">-->
<!--            <div class="progress form-group">-->
<!--                <div id="down_progress" class="progress-bar progress-bar-success" role="progressbar"-->
<!--                     aria-valuenow="60" aria-valuemin="0" aria-valuemax="100"-->
<!--                     style="width: 90%;">-->
<!--                    <span class="sr-only">0% 完成（成功）</span>-->
<!--                </div>-->
<!--            </div>-->
<!--        </div>-->
<!--    </div>-->



    <div class="form-group">
        <div class="col-xs-2"></div>
        <div class="col-xs-12 col-sm-8">
            <button onclick="createTable();" type="button" class="btn btn-default btn-embossed">{:__('submit')}</button>
        </div>
    </div>
</form>
<style>
    #ribbon{display: none;}
</style>


<script>

    var partition_num= 50;
    function createTable() {
            var num = $("#num").val();
            if( num >1000){
                parent.layer.closeAll();
                parent.Toastr.error( '最多一次生成500张');
                return false;
            }
            var number = Math.ceil( num / partition_num );

            subCreate( num , number);
    }

    function subCreate( num  , number){
        if( number <= 0){
            parent.Toastr.success( '生成成功');
            parent.layer.closeAll();
            parent.$(".btn-refresh").click();
            return true;
        }
        if( num  > partition_num){
            that_num = partition_num;
        } else {
            that_num = num;
        }

        $.ajax({
            url: "{:url('create_qrcode')}",
            data: {
                num:that_num
            },
            method:'post',
            dataType: "json",
            success: function(ret){
               // $("#down_progress_lable").text( "正在打包("+ (100 / number) + "%)");
               // $("#down_progress").css( 'width' , (100 / number) + "%");
                subCreate( num - partition_num , number-1 );
                console.log(ret);
            },
            error:function(){
                Toastr.success( '网络连接失败，请稍后再试');
                return false;
            }
        });

    }
</script>
